package com.cb.controller;

import com.cb.pojo.FilmAccess;
import com.cb.service.LeaderboardService;
import com.cb.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.HashMap;

@RestController
@RequestMapping("/leaderboard")
public class LeaderboardController {

    @Autowired
    UserService userService;
    @Autowired
    LeaderboardService leaderboardService;
    /**
     * 用户点击一部电影，增加访问量
     * @param filmAccess
     */
    @PostMapping("/filmaccess")
    @ApiOperation(value = "用户点击一部电影，增加访问量", notes = "用户点击一部电影，增加访问量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ypid", value = "id就是表的id，随便传一个，但是不能为空"),
            @ApiImplicitParam(name = "ypid", value = "影片编号"),
            @ApiImplicitParam(name = "ypname", value = "影片名字"),
            @ApiImplicitParam(name = "fnumber", value = "传入1就行")
    })
    public void filmAccess(@RequestBody HashMap json, HttpServletRequest request){
        //redisCacheTemplate.opsForValue().set("RedisSortSetLength","0");
        FilmAccess filmAccess = new FilmAccess();
        filmAccess.setId(Integer.parseInt(String.valueOf(json.get("id"))))
                .setYpid(String.valueOf(json.get("ypid")))
                .setYpname(String.valueOf(json.get("ypname")))
                .setFnumber(Integer.parseInt(String.valueOf(json.get("fnumber"))));
        userService.filmaccess(filmAccess);
    }

    @PostMapping("/anticipation")
    @ApiOperation(value = "用户点击想看一部电影，做期待排行榜", notes = "用户点击想看一部电影，做期待排行榜")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ypid", value = "影片编号"),
            @ApiImplicitParam(name = "ypname", value = "影片名字")
    })
    public String anticipation(@RequestBody HashMap json, HttpServletRequest request){
        return leaderboardService.anticipation(json,request);
    }

    @PostMapping("/xianAnticipation")
    @ResponseBody
    @ApiOperation(value = "显示期待排行榜", notes = "显示待排行榜")
    @ApiImplicitParams({

    })
    public String xianAnticipation(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return leaderboardService.xianAnticipation(json,request);
    }

    @PostMapping("/allOrderListRedis")
    @ResponseBody
    @ApiOperation(value = "显示总排行榜", notes = "总排行榜")
    @ApiImplicitParams({

    })
    public String allOrderListRedis(@RequestBody HashMap json,HttpServletRequest request) throws ParseException {
        return leaderboardService.allOrderListRedis(json,request);
    }
}
